import { upload } from "api/common/common";

function uploadimg(event) {
    let img = event
    let type = img.type
    let size = img.size
    let result = {
        photos: '',
        msg: '',
        success: true
    }
    let typelist = 'image/jpeg, image/png, image/jpg'

    if (size > 5242880) {
        this.$toast('上传图片不能大于5m')
        return false;
    }
    let form = new FormData()
    form.append('photos', img)

    return upload(form).then(res => {

        if (res.status != 1) {
            result = {
                photos: null,
                success: res.success,
                msg: res.msg
            }
            return Promise.reject(result)
        }

        result = {
            photos: res.result[0],
            success: res.success,
            msg: res.msg
        }
        
        return Promise.resolve(result)
    }).catch(error => {
        result = {
            photos: null,
            success: false,
            msg: error.msg
        }
        return Promise.reject(result)
    })
}

export default uploadimg